package org.gap.service;

import java.util.List;
import java.util.Set;

import org.gap.domain.Patient;
import org.gap.domain.RendezVous;
import org.gap.domain.Tiers;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/GAP_v2-security-context.xml",
		"file:./resources/GAP_v2-service-context.xml",
		"file:./resources/GAP_v2-dao-context.xml",
		"file:./resources/GAP_v2-web-context.xml" })
@Transactional
public class PatientServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected PatientService service;

	/**
	 * Instantiates a new PatientServiceTest.
	 *
	 */
	public PatientServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Patient entity
	 * 
	 */
	@Test
	public void deletePatient() {
		// TODO: JUnit - Populate test inputs for operation: deletePatient 
		Patient patient = new org.gap.domain.Patient();
		service.deletePatient(patient);
	}

	/**
	 * Operation Unit Test
	 * Load an existing Patient entity
	 * 
	 */
	@Test
	public void loadPatients() {
		Set<Patient> response = null;
		response = service.loadPatients();
		// TODO: JUnit - Add assertions to test outputs of operation: loadPatients
	}

	/**
	 * Operation Unit Test
	 * Save an existing Patient entity
	 * 
	 */
	@Test
	public void savePatient() {
		// TODO: JUnit - Populate test inputs for operation: savePatient 
		Patient patient_1 = new org.gap.domain.Patient();
		service.savePatient(patient_1);
	}

	/**
	 * Operation Unit Test
	 * Save an existing RendezVous entity
	 * 
	 */
	@Test
	public void savePatientRendezVouses() {
		// TODO: JUnit - Populate test inputs for operation: savePatientRendezVouses 
		Integer patPatient = 0;
		RendezVous related_rendezvouses = new org.gap.domain.RendezVous();
		Patient response = null;
		response = service.savePatientRendezVouses(patPatient, related_rendezvouses);
		// TODO: JUnit - Add assertions to test outputs of operation: savePatientRendezVouses
	}

	/**
	 * Operation Unit Test
	 * Return all Patient entity
	 * 
	 */
	@Test
	public void findAllPatients() {
		// TODO: JUnit - Populate test inputs for operation: findAllPatients 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Patient> response = null;
		response = service.findAllPatients(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllPatients
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Tiers entity
	 * 
	 */
	@Test
	public void deletePatientTiers() {
		// TODO: JUnit - Populate test inputs for operation: deletePatientTiers 
		Integer patient_patPatient = 0;
		Integer related_tiers_tieTiers = 0;
		Patient response = null;
		response = service.deletePatientTiers(patient_patPatient, related_tiers_tieTiers);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePatientTiers
	}

	/**
	 * Operation Unit Test
	 * Save an existing Tiers entity
	 * 
	 */
	@Test
	public void savePatientTiers() {
		// TODO: JUnit - Populate test inputs for operation: savePatientTiers 
		Integer patPatient_1 = 0;
		Tiers related_tiers = new org.gap.domain.Tiers();
		Patient response = null;
		response = service.savePatientTiers(patPatient_1, related_tiers);
		// TODO: JUnit - Add assertions to test outputs of operation: savePatientTiers
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findPatientByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findPatientByPrimaryKey 
		Integer patPatient_2 = 0;
		Patient response = null;
		response = service.findPatientByPrimaryKey(patPatient_2);
		// TODO: JUnit - Add assertions to test outputs of operation: findPatientByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Delete an existing RendezVous entity
	 * 
	 */
	@Test
	public void deletePatientRendezVouses() {
		// TODO: JUnit - Populate test inputs for operation: deletePatientRendezVouses 
		Integer patient_patPatient_1 = 0;
		Integer related_rendezvouses_rdvRendezVous = 0;
		Patient response = null;
		response = service.deletePatientRendezVouses(patient_patPatient_1, related_rendezvouses_rdvRendezVous);
		// TODO: JUnit - Add assertions to test outputs of operation: deletePatientRendezVouses
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Patient entity
	 * 
	 */
	@Test
	public void countPatients() {
		Integer response = null;
		response = service.countPatients();
		// TODO: JUnit - Add assertions to test outputs of operation: countPatients
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
